package com.example.demo.service.Impl;


import com.example.demo.dao.IDepartment;
import com.example.demo.model.Department;
import com.example.demo.service.IDepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Administrator 张喜英
 */

@Service
public class DepartmentServiceImpl implements IDepartmentService{

    @Autowired
    private IDepartment departmentMapper;
    @Override
    public List<Department> query(int bmid) {
        return departmentMapper.query(bmid);
    }
    @Override
    public int insertDepartment(Department department){
        int departmentValue=0;

        Department department1=new Department();
        department1.setBmid(department.getBmid());
        List<Department> getU=departmentMapper.getAllDepartment(department1);
        if(getU.size()>0){
            departmentValue=-1;

        }else{
            departmentValue=departmentMapper.insertDepartment(department);
        }

        return departmentValue;
    }

    @Override
    public List<Department> getAllDepartment(Department department) {


        return departmentMapper.getAllDepartment(department);
    }

    @Override
    public int updateDepartment(Department department) {
        int departmentValues=0;
        if(department.getBmid()!=0){

            departmentValues=departmentMapper.updateDepartment(department);
        }
        return departmentValues;
    }

    @Override
    public int deleteDepartment(Department department) {
        int departmentValues=0;
        if(department.getBmid()!=0)
        {
            //主键是否与其他表有关联

            departmentValues=departmentMapper.deleteDepartment(department);
        }
        return departmentValues;
    }

    @Override
    public Department getDepartment(Department department) {
        Department department1=new Department();
        if(department.getBmid()!=0){
            department1=departmentMapper.getDepartment(department);
        }
        return department1;
    }

}
